// 核心游戏场景 - 重构后的主要游戏逻辑
class PixelSurvivor extends Phaser.Scene {
    constructor() {
        super({ key: 'PixelSurvivor' });
        this.resetGameState();
    }

    resetGameState() {
        // 游戏状态
        this.player = null;
        this.enemies = null;
        this.bullets = null;
        this.wave = 1;
        this.enemiesKilled = 0;
        this.gameTime = 0;
        this.gold = 0;

        // 波数计时系统
        this.waveTimer = null;
        this.countdownTimer = null;
        this.waveCountdownText = null;
        this.baseWaveTime = 20000; // 基础波次时间（20秒，原为30秒）
        this.minWaveTime = 15000;  // 最短波次时间（15秒，原为20秒）
        this.maxWaveTime = 40000;  // 最长波次时间（40秒，原为60秒）

        // 暂停相关状态
        this.pausedWaveTimeRemaining = null; // 暂停时的剩余时间
        this.currentWaveTime = null; // 当前波次的总时间
        this.isManuallyPaused = false; // 手动暂停状态

        // 玩家属性 - 重置为默认值
        this.playerStats = { ...GameConfig.playerDefaults };

        this.lastFired = 0;
        this.weapons = ['pistol'];
        this.isUpgrading = false;
        this.isShopOpen = false;  // 商店状态标志
        this.upgradeOptions = [];

        // Boss系统
        this.isBossWave = false;
        this.currentBoss = null;
        this.enemyBullets = null;
        this.bossesKilled = 0;

        // 粒子系统
        this.particles = null;

        // 道具系统
        this.pickups = null;
        this.experiencePoints = 0;
        this.playerLevel = 1;
        this.expToNextLevel = 50;
        this.totalExpNeeded = 50;

        // 系统初始化
        this.weaponSystem = null;
        this.enemySystem = null;
        this.upgradeSystem = null;
        this.uiSystem = null;
        this.achievementSystem = null;
        this.touchController = null;
        this.shopSystem = null;
    }

    preload() {
        SpriteCreator.createPixelSprites(this);
    }

    create() {
        // 重置游戏状态
        this.resetGameState();

        // 创建更大的背景
        this.createGameBackground();

        // 初始化系统
        this.weaponSystem = new WeaponSystem(this);
        this.enemySystem = new EnemySystem(this);
        this.upgradeSystem = new UpgradeSystem(this);
        this.uiSystem = new UISystem(this);
        this.achievementSystem = new AchievementSystem(this);
        this.touchController = new TouchController(this);
        this.shopSystem = new ShopSystem(this);  // 初始化商店系统

        // 移除商店快捷键
        // this.input.keyboard.on('keydown-S', () => {
        //     if (!this.isUpgrading) {
        //         this.shopSystem.showShop();
        //     }
        // });

        // 创建玩家 - 放在游戏区域中心（考虑墙体）
        const wallThickness = 32;
        const gameAreaCenterX = wallThickness + (2400 - wallThickness * 2) / 2;
        const gameAreaCenterY = wallThickness + (1800 - wallThickness * 2) / 2;
        this.player = this.physics.add.sprite(gameAreaCenterX, gameAreaCenterY, 'player');
        this.player.setCollideWorldBounds(true);

        // 设置摄像机跟随玩家
        this.cameras.main.startFollow(this.player);
        this.cameras.main.setFollowOffset(0, 0);
        this.cameras.main.setLerp(0.1, 0.1);
        this.cameras.main.setBounds(0, 0, 2400, 1800);

        // 创建组
        this.enemies = this.physics.add.group();
        this.bullets = this.physics.add.group();
        this.enemyBullets = this.physics.add.group();
        this.pickups = this.physics.add.group();

        // 创建粒子系统
        EffectSystem.createParticles(this);

        // 碰撞检测
        this.physics.add.overlap(this.bullets, this.enemies, this.hitEnemy, null, this);
        this.physics.add.overlap(this.player, this.enemies, this.playerHit, null, this);
        this.physics.add.overlap(this.player, this.enemyBullets, this.playerHitByBullet, null, this);
        this.physics.add.overlap(this.player, this.pickups, this.collectPickup, null, this);
        
        // 延迟添加墙体碰撞，确保worldWalls已创建
        this.time.delayedCall(100, () => {
            // 子弹与墙体碰撞
            if (this.worldWalls) {
                this.physics.add.collider(this.bullets, this.worldWalls, (bullet, wall) => {
                    if (bullet && bullet.active) {
                        EffectSystem.createImpact(this, bullet.x, bullet.y);
                        bullet.destroy();
                    }
                });
                
                // 敌人子弹与墙体碰撞
                this.physics.add.collider(this.enemyBullets, this.worldWalls, (bullet, wall) => {
                    if (bullet && bullet.active) {
                        EffectSystem.createImpact(this, bullet.x, bullet.y);
                        bullet.destroy();
                    }
                });
            }
        });

        // 键盘控制
        this.cursors = this.input.keyboard.createCursorKeys();
        this.wasd = this.input.keyboard.addKeys('W,S,A,D');

        // 暂停键
        this.pauseKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.ESC);
        this.pauseKey.on('down', () => {
            this.togglePause();
        });

        // 开始生成敌人 - 大量生成，动态调整
        this.spawnEnemyTimer = this.time.addEvent({
            delay: 500,
            callback: () => {
                // 如果是Boss波次且Boss还活着，不生成普通敌人
                if (this.isBossWave && this.currentBoss) {
                    return;
                }

                // 根据波次动态调整敌人数量和生成频率
                const baseEnemyCount = Math.min(1 + Math.floor(this.wave / 2), 6);
                
                let enemyCount = baseEnemyCount;
                const randomFactor = Math.random();
                
                if (randomFactor < 0.1) {
                    enemyCount = baseEnemyCount + Math.floor(Math.random() * 3) + 2;
                    EffectSystem.showFloatingText(this, this.player.x, this.player.y - 50, "敌群来袭!", '#ff0000');
                }
                
                for (let i = 0; i < enemyCount; i++) {
                    this.time.delayedCall(i * 100, () => {
                        this.enemySystem.spawnEnemy(this.wave);
                    });
                }
                
                const nextDelay = Phaser.Math.Between(400, 800);
                this.spawnEnemyTimer.delay = nextDelay;
                this.spawnEnemyTimer.reset({
                    delay: nextDelay,
                    callback: this.spawnEnemyTimer.callback,
                    callbackScope: this,
                    loop: true
                });
            },
            callbackScope: this,
            loop: true
        });

        // 初始化波数计时器
        this.startWaveTimer();

        // 延迟创建UI，确保摄像机已设置
        this.time.delayedCall(50, () => {
            this.uiSystem.createGameUI();
        });
    }

    createGameBackground() {
        // 创建多层背景纹理
        const tileSize = 64;
        const worldWidth = 2400;
        const worldHeight = 1800;
        
        // 主要地面纹理
        this.add.graphics()
            .fillStyle(0x1a1a2e)
            .fillRect(0, 0, tileSize, tileSize)
            .lineStyle(1, 0x16213e, 0.3)
            .strokeRect(0, 0, tileSize, tileSize)
            .generateTexture('ground_tile', tileSize, tileSize);

        // 创建带纹理的地面块
        this.add.graphics()
            .fillStyle(0x1e1e32)
            .fillRect(0, 0, tileSize, tileSize)
            .fillStyle(0x151526, 0.6)
            .fillRect(8, 8, 12, 12)
            .fillRect(44, 20, 8, 8)
            .fillRect(20, 40, 16, 10)
            .lineStyle(1, 0x16213e, 0.4)
            .strokeRect(0, 0, tileSize, tileSize)
            .generateTexture('ground_texture', tileSize, tileSize);

        // 创建岩石纹理
        this.add.graphics()
            .fillStyle(0x2a2a3e)
            .fillRect(0, 0, tileSize, tileSize)
            .fillStyle(0x35354a, 0.8)
            .fillCircle(16, 16, 6)
            .fillCircle(48, 32, 4)
            .fillCircle(32, 48, 5)
            .lineStyle(1, 0x16213e, 0.3)
            .strokeRect(0, 0, tileSize, tileSize)
            .generateTexture('stone_tile', tileSize, tileSize);

        // 创建草地纹理
        this.add.graphics()
            .fillStyle(0x1a2e1a)
            .fillRect(0, 0, tileSize, tileSize)
            .fillStyle(0x2d4a2d, 0.7)
            .fillRect(4, 12, 2, 8)
            .fillRect(20, 8, 3, 6)
            .fillRect(45, 15, 2, 10)
            .fillRect(30, 35, 3, 7)
            .fillRect(50, 45, 2, 6)
            .fillRect(12, 48, 3, 8)
            .lineStyle(1, 0x16213e, 0.2)
            .strokeRect(0, 0, tileSize, tileSize)
            .generateTexture('grass_tile', tileSize, tileSize);

        // 平铺背景 - 混合不同纹理
        for (let x = 0; x < worldWidth; x += tileSize) {
            for (let y = 0; y < worldHeight; y += tileSize) {
                const random = Math.random();
                let texture = 'ground_tile';
                
                // 随机选择纹理类型
                if (random < 0.6) {
                    texture = 'ground_tile';
                } else if (random < 0.8) {
                    texture = 'ground_texture';
                } else if (random < 0.92) {
                    texture = 'stone_tile';
                } else {
                    texture = 'grass_tile';
                }
                
                this.add.image(x + tileSize/2, y + tileSize/2, texture);
            }
        }

        // 添加一些装饰性元素增强移动感
        this.createDecorations();
        
        // 创建世界边界墙体
        this.createWorldBoundaries();
    }

    createDecorations() {
        const worldWidth = 2400;
        const worldHeight = 1800;
        const wallThickness = 32;
        
        // 创建装饰石头纹理
        this.add.graphics()
            .fillStyle(0x4a4a5a)
            .fillCircle(8, 8, 8)
            .fillStyle(0x3a3a4a, 0.8)
            .fillCircle(8, 8, 6)
            .generateTexture('deco_stone', 16, 16);

        // 创建装饰植物纹理
        this.add.graphics()
            .fillStyle(0x2d5a2d)
            .fillRect(6, 10, 4, 6)
            .fillRect(4, 8, 8, 3)
            .fillStyle(0x1a4a1a)
            .fillRect(7, 11, 2, 4)
            .generateTexture('deco_plant', 16, 16);

        // 创建小道路标记
        this.add.graphics()
            .fillStyle(0x3a3a4a, 0.6)
            .fillRect(0, 6, 32, 4)
            .fillRect(6, 0, 4, 32)
            .generateTexture('path_marker', 32, 32);

        // 随机放置装饰物
        for (let i = 0; i < 200; i++) {
            const x = Phaser.Math.Between(wallThickness + 50, worldWidth - wallThickness - 50);
            const y = Phaser.Math.Between(wallThickness + 50, worldHeight - wallThickness - 50);
            
            // 避免在玩家出生点附近放置
            const playerSpawnX = wallThickness + (worldWidth - wallThickness * 2) / 2;
            const playerSpawnY = wallThickness + (worldHeight - wallThickness * 2) / 2;
            const distanceFromSpawn = Phaser.Math.Distance.Between(x, y, playerSpawnX, playerSpawnY);
            
            if (distanceFromSpawn > 200) {
                const random = Math.random();
                if (random < 0.6) {
                    this.add.image(x, y, 'deco_stone').setAlpha(0.8);
                } else if (random < 0.9) {
                    this.add.image(x, y, 'deco_plant').setAlpha(0.7);
                } else {
                    this.add.image(x, y, 'path_marker').setAlpha(0.5);
                }
            }
        }

        // 在边界附近添加一些大石头作为地标
        const landmarks = [
            {x: 200, y: 200}, {x: 2200, y: 200}, 
            {x: 200, y: 1600}, {x: 2200, y: 1600},
            {x: 1200, y: 200}, {x: 1200, y: 1600},
            {x: 200, y: 900}, {x: 2200, y: 900}
        ];

        // 创建地标石头纹理
        this.add.graphics()
            .fillStyle(0x5a5a6a)
            .fillCircle(16, 16, 16)
            .fillStyle(0x4a4a5a, 0.9)
            .fillCircle(16, 16, 13)
            .fillStyle(0x6a6a7a, 0.5)
            .fillCircle(12, 12, 6)
            .generateTexture('landmark_stone', 32, 32);

        landmarks.forEach(landmark => {
            this.add.image(landmark.x, landmark.y, 'landmark_stone').setAlpha(0.9);
        });
    }

    createWorldBoundaries() {
        const wallThickness = 32;
        const worldWidth = 2400;
        const worldHeight = 1800;
        
        // 创建墙体纹理
        this.add.graphics()
            .fillStyle(0x8b4513)
            .fillRect(0, 0, wallThickness, wallThickness)
            .lineStyle(2, 0x654321)
            .strokeRect(0, 0, wallThickness, wallThickness)
            .generateTexture('wall_tile', wallThickness, wallThickness);
        
        // 创建物理边界墙体组
        this.worldWalls = this.physics.add.staticGroup();
        
        // 上边界
        for (let x = 0; x < worldWidth; x += wallThickness) {
            const wall = this.worldWalls.create(x + wallThickness/2, wallThickness/2, 'wall_tile');
        }
        
        // 下边界
        for (let x = 0; x < worldWidth; x += wallThickness) {
            const wall = this.worldWalls.create(x + wallThickness/2, worldHeight - wallThickness/2, 'wall_tile');
        }
        
        // 左边界
        for (let y = wallThickness; y < worldHeight - wallThickness; y += wallThickness) {
            const wall = this.worldWalls.create(wallThickness/2, y + wallThickness/2, 'wall_tile');
        }
        
        // 右边界
        for (let y = wallThickness; y < worldHeight - wallThickness; y += wallThickness) {
            const wall = this.worldWalls.create(worldWidth - wallThickness/2, y + wallThickness/2, 'wall_tile');
        }
        
        // 添加墙体碰撞 - 添加安全检查
        if (this.worldWalls && this.player) {
            this.physics.add.collider(this.player, this.worldWalls);
        }
        
        // 设置实际的游戏区域边界 (墙体内部)
        this.physics.world.setBounds(wallThickness, wallThickness, 
                                   worldWidth - wallThickness * 2, 
                                   worldHeight - wallThickness * 2);
    }

    update(time, delta) {
        // 检查是否在升级菜单、商店、Boss奖励状态或手动暂停
        if (this.isUpgrading || this.isShopOpen || this.isManuallyPaused) {
            // 暂停所有游戏对象的物理运动
            this.enemies.children.entries.forEach(enemy => {
                if (enemy.body) {
                    enemy.body.setVelocity(0, 0);
                }
            });
            
            // 暂停玩家移动
            if (this.player && this.player.body) {
                this.player.body.setVelocity(0, 0);
            }
            
            // 暂停所有子弹
            this.bullets.children.entries.forEach(bullet => {
                if (bullet.body) {
                    bullet.body.setVelocity(0, 0);
                }
            });
            
            this.enemyBullets.children.entries.forEach(bullet => {
                if (bullet.body) {
                    bullet.body.setVelocity(0, 0);
                }
            });
            
            // 确保敌人生成计时器在游戏暂停时也暂停
            if (this.spawnEnemyTimer && !this.spawnEnemyTimer.paused) {
                this.spawnEnemyTimer.paused = true;
            }

            // 暂停波次计时器 - 完全停止并保存剩余时间
            if (this.waveTimer && this.currentWaveTime && !this.pausedWaveTimeRemaining) {
                // 计算剩余时间
                const elapsed = this.time.now - this.waveStartTime;
                this.pausedWaveTimeRemaining = Math.max(0, this.currentWaveTime - elapsed);
                console.log(`暂停游戏，剩余时间: ${this.pausedWaveTimeRemaining}ms`);

                // 完全移除计时器
                this.waveTimer.remove();
                this.waveTimer = null;

                if (this.countdownTimer) {
                    this.countdownTimer.remove();
                    this.countdownTimer = null;
                }
            }
            
            return; // 直接返回，不执行任何游戏逻辑
        }

        this.gameTime += delta;

        // 恢复游戏时重新启动计时器
        if (this.spawnEnemyTimer && this.spawnEnemyTimer.paused && !this.isBossWave) {
            this.spawnEnemyTimer.paused = false;
        }

        // 恢复波次计时器 - 使用保存的剩余时间
        if (this.pausedWaveTimeRemaining !== null && !this.waveTimer) {
            console.log(`恢复游戏，使用剩余时间: ${this.pausedWaveTimeRemaining}ms`);
            this.startWaveTimerWithRemainingTime(this.pausedWaveTimeRemaining);
            this.pausedWaveTimeRemaining = null;
        }

        // 只有在非暂停状态下才执行游戏逻辑
        if (this.touchController) {
            this.touchController.update();
        }

        this.handlePlayerMovement();
        this.handleAutoFire(time);
        this.enemySystem.updateEnemies();
        this.cleanupBullets();
        this.updatePickupAttraction();
        this.updatePlayerEffects(delta);
    }

    // 更新玩家效果（生命回复等）
    updatePlayerEffects(delta) {
        // 生命回复
        if (this.playerStats.healthRegen > 0 && this.playerStats.health < this.playerStats.maxHealth) {
            const regenAmount = (this.playerStats.healthRegen * delta) / 1000; // 每秒回复
            this.playerStats.health = Math.min(
                this.playerStats.maxHealth,
                this.playerStats.health + regenAmount
            );

            // 更新生命值显示
            if (this.uiSystem) {
                this.uiSystem.updateHealthText(this.playerStats.health);
            }
        }
    }

    handlePlayerMovement() {
        const speed = this.playerStats.speed;
        let isMoving = false;

        // 重置速度
        this.player.setVelocity(0);

        // 获取触摸控制输入
        const touchInput = this.touchController ? this.touchController.getMovementInput() : { x: 0, y: 0 };

        // 计算移动向量
        let moveX = 0;
        let moveY = 0;

        // WASD 或 方向键控制
        if (this.cursors.left.isDown || this.wasd.A.isDown || touchInput.x < -0.1) {
            moveX = touchInput.x ? touchInput.x : -1;
            isMoving = true;
        } else if (this.cursors.right.isDown || this.wasd.D.isDown || touchInput.x > 0.1) {
            moveX = touchInput.x ? touchInput.x : 1;
            isMoving = true;
        }

        if (this.cursors.up.isDown || this.wasd.W.isDown || touchInput.y < -0.1) {
            moveY = touchInput.y ? touchInput.y : -1;
            isMoving = true;
        } else if (this.cursors.down.isDown || this.wasd.S.isDown || touchInput.y > 0.1) {
            moveY = touchInput.y ? touchInput.y : 1;
            isMoving = true;
        }

        // 标准化移动向量，防止斜向移动过快，应用移动速度倍数
        if (moveX !== 0 || moveY !== 0) {
            const magnitude = Math.sqrt(moveX * moveX + moveY * moveY);
            const effectiveSpeed = speed * this.playerStats.moveSpeed;
            moveX = (moveX / magnitude) * effectiveSpeed;
            moveY = (moveY / magnitude) * effectiveSpeed;

            this.player.setVelocity(moveX, moveY);
        }

        // 玩家移动尾迹效果
        if (isMoving && Math.random() < 0.3) {
            this.trailParticles.emitParticleAt(this.player.x, this.player.y, 1);
        }
    }

    handleAutoFire(time) {
        // 应用攻击速度倍数
        const effectiveFireRate = this.playerStats.fireRate / this.playerStats.attackSpeed;

        if (time - this.lastFired > effectiveFireRate) {
            const nearestEnemy = this.weaponSystem.findNearestEnemy(this.player, this.enemies, this.playerStats.range);
            if (nearestEnemy) {
                this.weaponSystem.fireAtTarget(nearestEnemy, this.weapons, this.playerStats);
                this.lastFired = time;
            }
        }
    }

    cleanupBullets() {
        // 清理超出世界边界的子弹 - 添加安全检查
        if (this.bullets && this.bullets.children) {
            this.bullets.children.entries.forEach(bullet => {
                if (bullet && bullet.active && (bullet.x < -100 || bullet.x > 2500 || bullet.y < -100 || bullet.y > 1900)) {
                    bullet.destroy();
                }
            });
        }

        // 清理敌人子弹
        if (this.enemyBullets && this.enemyBullets.children) {
            this.enemyBullets.children.entries.forEach(bullet => {
                if (bullet && bullet.active && (bullet.x < -100 || bullet.x > 2500 || bullet.y < -100 || bullet.y > 1900)) {
                    bullet.destroy();
                }
            });
        }

        // 清理无效的子弹（没有速度的子弹或存在时间过长的子弹）
        if (this.bullets && this.bullets.children) {
            this.bullets.children.entries.forEach(bullet => {
                if (bullet && bullet.active && bullet.body) {
                    // 如果子弹速度为0且不在暂停状态，删除它
                    if (!this.isUpgrading && bullet.body.velocity.x === 0 && bullet.body.velocity.y === 0) {
                        console.log('清理速度为0的子弹');
                        bullet.destroy();
                        return;
                    }

                    // 为子弹添加生命周期检查（防止子弹永远存在）
                    if (!bullet.createdTime) {
                        bullet.createdTime = this.time.now;
                    }

                    // 普通子弹最多存在5秒，激光子弹最多存在3秒
                    const maxLifetime = bullet.weaponType === 'laser' ? 3000 : 5000;
                    if (this.time.now - bullet.createdTime > maxLifetime) {
                        console.log(`清理存在时间过长的子弹: ${bullet.weaponType || 'normal'}`);
                        bullet.destroy();
                    }
                }
            });
        }

        // 清理敌人子弹的无效状态
        if (this.enemyBullets && this.enemyBullets.children) {
            this.enemyBullets.children.entries.forEach(bullet => {
                if (bullet && bullet.active && bullet.body) {
                    // 如果敌人子弹速度为0且不在暂停状态，删除它
                    if (!this.isUpgrading && bullet.body.velocity.x === 0 && bullet.body.velocity.y === 0) {
                        bullet.destroy();
                        return;
                    }

                    // 敌人子弹最多存在8秒
                    if (!bullet.createdTime) {
                        bullet.createdTime = this.time.now;
                    }

                    if (this.time.now - bullet.createdTime > 8000) {
                        bullet.destroy();
                    }
                }
            });
        }

        // 清理超出范围的敌人（防止敌人卡在墙外）
        if (this.enemies && this.enemies.children && this.player) {
            this.enemies.children.entries.forEach(enemy => {
                if (enemy && enemy.active) {
                    const distanceFromPlayer = Phaser.Math.Distance.Between(
                        this.player.x, this.player.y, enemy.x, enemy.y
                    );
                    
                    // 如果敌人距离玩家太远（超过1500像素），删除它
                    if (distanceFromPlayer > 1500) {
                        if (enemy.healthBar && enemy.healthBar.destroy) enemy.healthBar.destroy();
                        if (enemy.healthBarBg && enemy.healthBarBg.destroy) enemy.healthBarBg.destroy();
                        if (enemy.bossHealthBg && enemy.bossHealthBg.destroy) enemy.bossHealthBg.destroy();
                        if (enemy.bossHealthFg && enemy.bossHealthFg.destroy) enemy.bossHealthFg.destroy();
                        if (enemy.bossHealthText && enemy.bossHealthText.destroy) enemy.bossHealthText.destroy();
                        enemy.destroy();
                    }
                }
            });
        }
    }

    updatePickupAttraction() {
        this.pickups.children.entries.forEach(pickup => {
            if (pickup.pickupType === 'exp_gem') {
                const distance = Phaser.Math.Distance.Between(
                    this.player.x, this.player.y,
                    pickup.x, pickup.y
                );

                // 当玩家靠近时自动吸引
                if (distance < 150) {
                    // 标记为正在被吸引，停止其他动画
                    if (!pickup.isBeingAttracted) {
                        pickup.isBeingAttracted = true;
                        // 停止所有动画效果
                        this.tweens.killTweensOf(pickup);
                        // 重置缩放
                        pickup.setScale(1);
                    }

                    const angle = Phaser.Math.Angle.Between(
                        pickup.x, pickup.y,
                        this.player.x, this.player.y
                    );

                    // 距离越近，吸引速度越快
                    const speed = 200 + (150 - distance) * 2;

                    pickup.setVelocity(
                        Math.cos(angle) * speed,
                        Math.sin(angle) * speed
                    );
                } else {
                    // 不在吸引范围内，重置状态
                    if (pickup.isBeingAttracted) {
                        pickup.isBeingAttracted = false;
                        pickup.setVelocity(0, 0); // 停止移动

                        // 重新启动缩放动画
                        this.tweens.add({
                            targets: pickup,
                            scaleX: 1.1,
                            scaleY: 1.1,
                            duration: 800,
                            yoyo: true,
                            repeat: -1,
                            ease: 'Sine.easeInOut'
                        });
                    }
                }
            }
        });
    }

    hitEnemy(bullet, enemy) {
        // 计算伤害（包含暴击）
        let damage = bullet.damage || this.playerStats.damage;
        const isCrit = Math.random() < this.playerStats.critChance;
        if (isCrit) {
            damage *= this.playerStats.critDamage;
            EffectSystem.createDamageText(this, enemy.x, enemy.y, Math.floor(damage), true);
        } else {
            EffectSystem.createDamageText(this, enemy.x, enemy.y, Math.floor(damage), false);
        }

        enemy.health -= damage;

        // 生命偷取效果
        if (this.playerStats.lifeSteal > 0) {
            const healAmount = damage * this.playerStats.lifeSteal;
            this.playerStats.health = Math.min(
                this.playerStats.maxHealth,
                this.playerStats.health + healAmount
            );

            // 显示治疗效果
            if (healAmount > 0.5) {
                EffectSystem.showFloatingText(this, this.player.x, this.player.y - 20, `+${Math.floor(healAmount)}`, '#00ff00');

                // 更新生命值显示
                if (this.uiSystem) {
                    this.uiSystem.updateHealthText(this.playerStats.health);
                }
            }
        }

        // 穿透逻辑 - 修复子弹不消失的问题
        bullet.piercedEnemies = (bullet.piercedEnemies || 0) + 1;

        // 特殊武器类型处理
        if (bullet.weaponType === 'rocket') {
            // 火箭弹击中后立即爆炸，不管穿透值
            this.createRocketExplosion(bullet.x, bullet.y, bullet.damage);
            bullet.destroy();
        } else if (bullet.weaponType === 'electric') {
            // 电击弹的连锁伤害
            this.createElectricChain(bullet.x, bullet.y, bullet.damage, enemy);
            // 电击弹按正常穿透逻辑处理
            if (bullet.piercedEnemies > bullet.piercing) {
                bullet.destroy();
            }
        } else if (bullet.weaponType === 'laser') {
            // 激光武器有特殊的生命周期管理
            // 激光子弹在一定时间后自动消失，而不是依赖穿透计数
            if (!bullet.laserTimer) {
                bullet.laserTimer = this.time.delayedCall(2000, () => {
                    if (bullet && bullet.active) {
                        bullet.destroy();
                    }
                });
            }
        } else {
            // 普通子弹的穿透逻辑
            if (bullet.piercedEnemies > bullet.piercing) {
                bullet.destroy();
            }
        }

        if (enemy.health <= 0) {
            console.log(`敌人死亡，当前金币: ${this.gold}, 敌人类型: ${enemy.type}`);
            this.handleEnemyDeath(enemy);
            console.log(`击杀后金币: ${this.gold}`);
        }
    }

    // 波数计时系统
    startWaveTimer() {
        // 计算当前波次的持续时间
        const waveTime = this.calculateWaveTime();
        this.startWaveTimerWithRemainingTime(waveTime);
    }

    // 使用指定的剩余时间开始波次计时器
    startWaveTimerWithRemainingTime(remainingTime) {
        console.log(`波次计时器开始，剩余时间: ${remainingTime/1000}秒`);

        // 创建或重置波数计时器
        if (this.waveTimer) {
            this.waveTimer.remove();
        }
        if (this.countdownTimer) {
            this.countdownTimer.remove();
        }

        // 记录波次开始时间和总时间
        this.waveStartTime = this.time.now;
        this.currentWaveTime = remainingTime;

        // 创建倒计时更新事件
        this.countdownTimer = this.time.addEvent({
            delay: 100, // 每100ms更新一次，提高精度
            callback: () => {
                if (this.waveCountdownText) {
                    // 计算剩余时间，基于当前波次时间
                    const elapsed = this.time.now - this.waveStartTime;
                    const timeLeft = Math.max(0, Math.ceil((this.currentWaveTime - elapsed) / 1000));

                    if (this.isBossWave && this.currentBoss && this.currentBoss.active) {
                        this.waveCountdownText.setText(`Boss战斗中`).setColor('#ff0000');
                    } else {
                        this.waveCountdownText.setText(`下一波: ${timeLeft}秒`).setColor('#00ff00');
                    }
                }
            },
            callbackScope: this,
            loop: true
        });

        this.waveTimer = this.time.addEvent({
            delay: remainingTime,
            callback: () => {
                // 如果当前是Boss波且Boss还活着，延长计时器等待Boss被击败
                if (this.isBossWave && this.currentBoss && this.currentBoss.active) {
                    console.log('Boss尚未击败，延长计时器等待');
                    // 延长5秒后再次检查
                    this.waveTimer = this.time.addEvent({
                        delay: 5000,
                        callback: this.waveTimer.callback,
                        callbackScope: this
                    });
                    return;
                }

                // 如果当前是Boss波但Boss已经死亡，跳过这次波次增加
                // 因为Boss死亡时已经处理了波次增加
                if (this.isBossWave && !this.currentBoss) {
                    console.log('Boss已死亡，跳过波次增加，直接开始下一波计时');
                    this.startWaveTimer();
                    return;
                }

                // 增加波数
                this.wave++;
                console.log(`波次增加到: ${this.wave}`);
                if (this.uiSystem) {
                    this.uiSystem.updateWaveText();
                }

                // 每5波出现Boss
                if (this.wave % 5 === 0) {
                    console.log(`第${this.wave}波是Boss波，生成Boss`);
                    this.enemySystem.spawnBoss(this.wave);
                    // Boss波只显示升级菜单，不显示商店
                    this.showUpgradeMenu();
                } else {
                    console.log(`第${this.wave}波是普通波，显示商店和升级菜单`);
                    // 非Boss波次时先显示商店，再显示升级菜单
                    this.shopSystem.showShop();
                    // 延迟显示升级菜单，避免冲突
                    this.time.delayedCall(100, () => {
                        this.showUpgradeMenu();
                    });
                }

                // 开始下一波计时
                this.startWaveTimer();
            },
            callbackScope: this
        });
    }

    calculateWaveTime() {
        // 波数越高，时间越长，但有上限
        const waveTime = this.baseWaveTime + (this.wave - 1) * 2000; // 每波增加2秒
        return Phaser.Math.Clamp(waveTime, this.minWaveTime, this.maxWaveTime);
    }

    handleEnemyDeath(enemy) {
        console.log(`开始处理敌人死亡，类型: ${enemy.type}, 当前金币: ${this.gold}`);
        
        // 死亡爆炸效果和血液粒子
        EffectSystem.createExplosion(this, enemy.x, enemy.y);
        this.bloodParticles.emitParticleAt(enemy.x, enemy.y, 5);

        // 清理敌人血条
        if (enemy.healthBar) {
            enemy.healthBar.destroy();
            enemy.healthBarBg.destroy();
        }

        // 增加金币
        if (enemy.type === 'boss') {
            console.log('处理Boss死亡奖励');
            // Boss掉落30个金币
            const coinCount = 30;
            for (let i = 0; i < coinCount; i++) {
                const offsetX = (Math.random() - 0.5) * 80;
                const offsetY = (Math.random() - 0.5) * 80;
                this.createPickup(enemy.x + offsetX, enemy.y + offsetY, 'gold');
            }
            // 应用金币倍数
            const bossGold = Math.floor(30 * this.playerStats.goldMultiplier);
            // 显示金币数
            EffectSystem.showFloatingText(this, enemy.x, enemy.y - 30, `+${bossGold} 金币`, '#FFD700');
            // 直接增加金币数
            this.gold += bossGold;
            console.log(`Boss击杀奖励后金币: ${this.gold}`);
        } else {
            // 普通敌人根据类型给予不同金币
            let goldAmount = 1; // 默认金币数
            
            // 根据敌人类型调整金币数量
            switch(enemy.type) {
                case 'fast':
                    goldAmount = 2;
                    break;
                case 'tank':
                    goldAmount = 3;
                    break;
                case 'normal':
                default:
                    goldAmount = 1;
                    break;
            }
            
            console.log(`普通敌人击杀，类型: ${enemy.type}, 奖励金币: ${goldAmount}`);
            // 应用金币倍数
            const finalGoldAmount = Math.floor(goldAmount * this.playerStats.goldMultiplier);
            // 增加金币
            this.gold += finalGoldAmount;
            // 显示金币
            EffectSystem.showFloatingText(this, enemy.x, enemy.y - 20, `+${finalGoldAmount} 金币`, '#FFD700');
        }

        // 更新UI中的金币显示
        if (this.uiSystem) {
            console.log(`更新UI金币显示为: ${this.gold}`);
            this.uiSystem.updateCoinText(this.gold);
        } else {
            console.log('警告: UI系统不存在');
        }

        // 掉落道具
        this.dropPickup(enemy.x, enemy.y, enemy.type);

        // Boss死亡处理
        if (enemy.type === 'boss') {
            this.handleBossDeath(enemy);
        } else {
            this.enemiesKilled++;
            this.achievementSystem.checkAchievements();
        }

        enemy.destroy();
        console.log(`敌人死亡处理完成，最终金币: ${this.gold}`);
    }

    handleBossDeath(boss) {
        console.log('Boss死亡处理开始');

        // 清理Boss血条和相关UI
        if (boss.bossHealthBg) {
            boss.bossHealthBg.destroy();
            if (boss.bossHealthFg) {
                boss.bossHealthFg.destroy();
            }
        }
        if (boss.bossText) {
            boss.bossText.destroy();
        }
        if (boss.indicator) {
            boss.indicator.destroy();
        }
        if (boss.distanceText) {
            boss.distanceText.destroy();
        }
        if (boss.bossIndicatorText) {
            boss.bossIndicatorText.destroy();
        }

        // 隐藏UISystem中的Boss血条
        if (this.uiSystem) {
            this.uiSystem.updateBossUI(null);
        }

        // Boss死亡特效
        // 多重爆炸效果
        for (let i = 0; i < 5; i++) {
            this.time.delayedCall(i * 200, () => {
                const offsetX = (Math.random() - 0.5) * 60;
                const offsetY = (Math.random() - 0.5) * 60;
                EffectSystem.createExplosion(this, boss.x + offsetX, boss.y + offsetY);
            });
        }

        // 增加Boss击杀计数
        this.bossesKilled++;

        // 检查成就
        this.achievementSystem.checkAchievements();

        // 重置Boss状态 - 立即重置，避免重复生成
        this.isBossWave = false;
        this.currentBoss = null;
        console.log('Boss状态已重置');

        // 恢复普通敌人生成
        if (this.spawnEnemyTimer) {
            this.spawnEnemyTimer.paused = false;
        }

        // Boss击败后立即进入下一波，避免等待计时器
        this.wave++;
        console.log(`Boss击败，波次增加到: ${this.wave}`);
        if (this.uiSystem) {
            this.uiSystem.updateWaveText();
        }

        // 停止当前的波次计时器，避免重复触发
        if (this.waveTimer) {
            this.waveTimer.remove();
            this.waveTimer = null;
        }
        if (this.countdownTimer) {
            this.countdownTimer.remove();
            this.countdownTimer = null;
        }

        // 重置暂停状态
        this.pausedWaveTimeRemaining = null;
        this.currentWaveTime = null;

        // Boss击败奖励 - 额外升级选择
        this.time.delayedCall(1000, () => {
            this.showBossRewardMenu();

            // 在显示奖励菜单后，延迟重新开始波次计时器
            this.time.delayedCall(2000, () => {
                console.log('Boss奖励处理完成，重新开始波次计时器');
                this.startWaveTimer();
            });
        });
    }

    playerHit(player, enemy) {
        // 应用防御力和闪避
        if (Math.random() < this.playerStats.dodgeChance) {
            // 闪避成功
            EffectSystem.showFloatingText(this, this.player.x, this.player.y - 20, 'DODGE!', '#00ffff');
            return;
        }

        // 计算实际伤害（应用防御力）
        const baseDamage = enemy.damage || 10;
        const actualDamage = Math.max(1, baseDamage - this.playerStats.defense);
        this.playerStats.health -= actualDamage;
        
        // 更新生命值显示
        if (this.uiSystem) {
            this.uiSystem.updateHealthText(this.playerStats.health);
        }

        // 清理敌人血条
        if (enemy.healthBar) {
            enemy.healthBar.destroy();
            enemy.healthBarBg.destroy();
        }

        enemy.destroy();

        // 受伤闪烁效果
        this.player.setTint(0xff0000);
        this.time.delayedCall(200, () => {
            this.player.clearTint();
        });

        if (this.playerStats.health <= 0) {
            this.gameOver();
        }
    }

    playerHitByBullet(player, bullet) {
        // 应用防御力和闪避
        if (Math.random() < this.playerStats.dodgeChance) {
            // 闪避成功
            EffectSystem.showFloatingText(this, this.player.x, this.player.y - 20, 'DODGE!', '#00ffff');
            return;
        }

        // 计算实际伤害（应用防御力）
        const baseDamage = bullet.damage || 15;
        const actualDamage = Math.max(1, baseDamage - this.playerStats.defense);
        this.playerStats.health -= actualDamage;
        
        // 更新生命值显示
        if (this.uiSystem) {
            this.uiSystem.updateHealthText(this.playerStats.health);
        }

        bullet.destroy();

        // 受伤闪烁效果
        this.player.setTint(0xff0000);
        this.time.delayedCall(200, () => {
            this.player.clearTint();
        });

        if (this.playerStats.health <= 0) {
            this.gameOver();
        }
    }

    showUpgradeMenu() {
        const upgradeOptions = this.upgradeSystem.generateUpgradeOptions();
        this.uiSystem.showUpgradeMenu(upgradeOptions);
    }

    showBossRewardMenu() {
        const bossRewards = this.upgradeSystem.generateBossRewards();
        this.uiSystem.showBossRewardMenu(bossRewards);
    }

    gameOver() {
        // 保存成就
        this.achievementSystem.checkAchievements();
        
        // 停止所有游戏逻辑
        this.physics.pause();
        this.isUpgrading = true; // 防止任何升级或商店操作
        
        // 停止所有计时器
        if (this.waveTimer) {
            this.waveTimer.remove();
        }
        if (this.countdownTimer) {
            this.countdownTimer.remove();
        }
        if (this.spawnEnemyTimer) {
            this.spawnEnemyTimer.remove();
        }
        
        // 清理所有敌人
        this.enemies.clear(true, true);
        this.enemyBullets.clear(true, true);
        this.bullets.clear(true, true);
        this.pickups.clear(true, true);
        
        // 停止所有粒子效果
        if (this.particles) {
            this.particles.destroy();
        }
        if (this.bloodParticles) {
            this.bloodParticles.destroy();
        }
        if (this.trailParticles) {
            this.trailParticles.destroy();
        }

        // 显示游戏结束界面
        const stats = {
            wave: this.wave,
            enemiesKilled: this.enemiesKilled,
            experiencePoints: this.experiencePoints,
            bossesKilled: this.bossesKilled,
            gold: this.gold
        };
        
        this.uiSystem.showGameOver(stats);
    }

    // 道具掉落系统
    dropPickup(x, y, enemyType) {
        // 每次都掉落经验
        this.createPickup(x, y, 'exp_gem');
        
        // 根据敌人类型和随机数决定额外掉落
        const dropChance = Math.random();
        let extraPickupType = null;

        if (enemyType === 'boss') {
            // Boss必定掉落多个道具
            this.createPickup(x - 30, y, 'exp_gem'); // 额外经验
            this.createPickup(x + 30, y, 'exp_gem'); // 额外经验
            this.createPickup(x, y - 30, 'health_pack');
            this.createPickup(x, y + 30, 'power_up');
            return;
        }

        // 普通敌人额外掉落概率
        if (dropChance < 0.15) {
            extraPickupType = 'health_pack'; // 15% 血包
        } else if (dropChance < 0.25) {
            extraPickupType = 'power_up'; // 10% 能量提升
        }

        if (extraPickupType) {
            this.createPickup(x + Phaser.Math.Between(-20, 20), 
                             y + Phaser.Math.Between(-20, 20), 
                             extraPickupType);
        }
    }

    createPickup(x, y, type) {
        const pickup = this.pickups.create(x, y, type);
        pickup.pickupType = type;
        
        if (type === 'gold') {
            // 金币特殊效果
            pickup.setScale(0.8);  // 稍微缩小一点
            
            // 随机初始速度
            const speed = 120;  // 增加一点初始速度
            const angle = Math.random() * Math.PI * 2;
            pickup.setVelocity(
                Math.cos(angle) * speed,
                Math.sin(angle) * speed
            );
            
            // 添加阻尼使金币逐渐停下
            pickup.setDrag(200);  // 增加阻尼以更快停下
            
            // 金币旋转动画
            this.tweens.add({
                targets: pickup,
                angle: 360,
                duration: 1000,
                repeat: -1
            });
            
            // 金币弹跳效果
            this.tweens.add({
                targets: pickup,
                y: y - 15,  // 增加弹跳高度
                duration: 600,
                yoyo: true,
                repeat: -1,
                ease: 'Sine.easeInOut'
            });
            
            // 金币闪光效果
            this.tweens.add({
                targets: pickup,
                alpha: 0.7,
                duration: 300,
                yoyo: true,
                repeat: -1,
                ease: 'Sine.easeInOut'
            });
            
            // 4秒后自动消失（给玩家更多时间收集）
            this.time.delayedCall(4000, () => {
                if (pickup && pickup.active) {
                    // 消失动画
                    this.tweens.add({
                        targets: pickup,
                        alpha: 0,
                        y: pickup.y - 20,
                        duration: 300,
                        ease: 'Cubic.easeOut',
                        onComplete: () => {
                            pickup.destroy();
                        }
                    });
                }
            });
        } else {
            // 其他道具的原有逻辑
            if (type !== 'exp_gem') {
                pickup.setVelocity(
                    (Math.random() - 0.5) * 100,
                    (Math.random() - 0.5) * 100
                );
            }

            // 道具闪烁效果
            this.tweens.add({
                targets: pickup,
                alpha: 0.5,
                duration: 500,
                yoyo: true,
                repeat: -1
            });
            
            if (type === 'exp_gem') {
                // 经验球设置物理属性，避免抖动
                pickup.setDrag(50); // 添加阻尼
                pickup.setBounce(0); // 不反弹
                pickup.isBeingAttracted = false; // 标记是否正在被吸引

                // 移除上下浮动效果，避免与吸引力冲突
                // 只保留轻微的缩放效果
                this.tweens.add({
                    targets: pickup,
                    scaleX: 1.1,
                    scaleY: 1.1,
                    duration: 800,
                    yoyo: true,
                    repeat: -1,
                    ease: 'Sine.easeInOut'
                });
            }

            // 道具自动消失
            this.time.delayedCall(10000, () => {
                if (pickup && pickup.active) {
                    pickup.destroy();
                }
            });
        }
    }

    collectPickup(player, pickup) {
        switch (pickup.pickupType) {
            case 'gold':
                // Boss掉落的金币已经在死亡时加过了，这里只播放特效
                if (pickup.active) {
                    this.particles.emitParticleAt(pickup.x, pickup.y, 3);
                }
                break;
            case 'exp_gem':
                // 增加经验值 - 应用经验倍数
                const baseExpGain = 10;
                const expGain = Math.floor(baseExpGain * this.playerStats.expMultiplier);
                this.experiencePoints += expGain;
                
                // 检查是否升级
                if (this.experiencePoints >= this.expToNextLevel) {
                    this.levelUp();
                } else {
                    // 更新经验条
                    if (this.expBar) {
                        const expRatio = this.experiencePoints / this.expToNextLevel;
                        this.expBar.scaleX = expRatio;
                    }
                    
                    // 更新经验文本
                    if (this.uiSystem) {
                        this.uiSystem.updateExpText();
                    }
                }
                
                // 只播放粒子特效
                this.particles.emitParticleAt(pickup.x, pickup.y, 3);
                break;

            case 'health_pack':
                const healAmount = 30;
                this.playerStats.health = Math.min(
                    this.playerStats.maxHealth,
                    this.playerStats.health + healAmount
                );
                this.healthText.setText(`生命: ${this.playerStats.health}`);

                // 治疗特效
                this.trailParticles.emitParticleAt(pickup.x, pickup.y, 8);
                break;

            case 'power_up':
                // 临时增益效果
                this.upgradeSystem.applyPowerUp();
                this.particles.emitParticleAt(pickup.x, pickup.y, 5);
                break;
        }

        pickup.destroy();
    }

    levelUp() {
        this.playerLevel++;
        
        // 计算下一级所需经验 - 大幅降低升级难度
        this.experiencePoints = 0;
        // 降低升级难度，每级经验值增长从30%降低到20%
        this.totalExpNeeded = Math.floor(this.totalExpNeeded * 1.2);
        this.expToNextLevel = this.totalExpNeeded;
        
        // 更新经验条
        if (this.expBar) {
            this.expBar.scaleX = 0;
        }
        
        // 更新经验文本
        if (this.uiSystem) {
            this.uiSystem.updateExpText();
        }
        
        // 升级特效
        this.particles.emitParticleAt(this.player.x, this.player.y, 20);
        
        // 显示升级文本
        EffectSystem.showFloatingText(this, this.player.x, this.player.y, `升级! 等级 ${this.playerLevel}`, '#00ff00');
        
        // 升级奖励 - 自动提升属性
        this.playerStats.damage += 2;
        this.playerStats.maxHealth += 10;
        this.playerStats.health = this.playerStats.maxHealth; // 升级时回满血
        this.healthText.setText(`生命: ${this.playerStats.health}`);
        
        // 显示升级菜单
        this.showUpgradeMenu();
    }

    // 切换暂停状态
    togglePause() {
        if (this.isUpgrading) {
            // 如果在升级菜单中，不允许暂停
            return;
        }

        this.isManuallyPaused = !this.isManuallyPaused;
        console.log(`游戏${this.isManuallyPaused ? '暂停' : '恢复'}`);

        if (this.isManuallyPaused) {
            // 显示角色属性面板
            this.uiSystem.showCharacterStats();
        } else {
            // 隐藏角色属性面板
            this.uiSystem.hideCharacterStats();
        }
    }

    // 火箭爆炸效果 - 范围伤害
    createRocketExplosion(x, y, damage) {
        // 创建爆炸视觉效果
        EffectSystem.createExplosion(this, x, y);

        // 屏幕震动
        this.cameras.main.shake(150, 0.02);

        // 范围伤害
        const explosionRadius = 80;
        this.enemies.children.entries.forEach(enemy => {
            if (enemy && enemy.active) {
                const distance = Phaser.Math.Distance.Between(x, y, enemy.x, enemy.y);
                if (distance <= explosionRadius) {
                    // 距离越近伤害越高
                    const damageMultiplier = 1 - (distance / explosionRadius);
                    const explosionDamage = damage * damageMultiplier * 0.8; // 爆炸伤害为原伤害的80%

                    enemy.health -= explosionDamage;
                    EffectSystem.createDamageText(this, enemy.x, enemy.y, Math.floor(explosionDamage), false);

                    if (enemy.health <= 0) {
                        this.handleEnemyDeath(enemy);
                    }
                }
            }
        });
    }

    // 电击连锁效果
    createElectricChain(x, y, damage, hitEnemy) {
        // 创建电击视觉效果
        this.particles.emitParticleAt(x, y, 8);

        // 寻找附近的敌人进行连锁
        const chainRadius = 120;
        const maxChainTargets = 3;
        let chainTargets = [];

        this.enemies.children.entries.forEach(enemy => {
            if (enemy && enemy.active && enemy !== hitEnemy) {
                const distance = Phaser.Math.Distance.Between(x, y, enemy.x, enemy.y);
                if (distance <= chainRadius) {
                    chainTargets.push({ enemy, distance });
                }
            }
        });

        // 按距离排序，选择最近的几个目标
        chainTargets.sort((a, b) => a.distance - b.distance);
        chainTargets = chainTargets.slice(0, maxChainTargets);

        // 对连锁目标造成伤害
        chainTargets.forEach((target, index) => {
            // 连锁伤害递减
            const chainDamage = damage * Math.pow(0.7, index + 1);

            // 延迟连锁效果
            this.time.delayedCall(100 * (index + 1), () => {
                if (target.enemy && target.enemy.active) {
                    target.enemy.health -= chainDamage;
                    EffectSystem.createDamageText(this, target.enemy.x, target.enemy.y, Math.floor(chainDamage), false);

                    // 创建电击连线效果
                    this.createElectricLine(x, y, target.enemy.x, target.enemy.y);

                    if (target.enemy.health <= 0) {
                        this.handleEnemyDeath(target.enemy);
                    }
                }
            });
        });
    }

    // 创建电击连线效果
    createElectricLine(x1, y1, x2, y2) {
        const line = this.add.graphics();
        line.lineStyle(2, 0x00ffff, 0.8);
        line.beginPath();
        line.moveTo(x1, y1);
        line.lineTo(x2, y2);
        line.strokePath();

        // 闪烁效果
        this.tweens.add({
            targets: line,
            alpha: 0,
            duration: 200,
            ease: 'Power2',
            onComplete: () => {
                line.destroy();
            }
        });
    }
}






